Through beam sensor with Digispark (ATtiny85 USB Development Board)

Through beam sensors can be used for a variety of applications, which include counting objects, number of steps move, etc. In this post, we will be looking at how do one interface this sensor with Digispark (ATtiny85 USB Development Board).

attiny85usb_main

Brief Overview

Digispark (ATtiny85 USB Board)

img_20160911_183446

Digispark is actually a development board with an ATtiny85 and USB connector, which makes programming the ATtiny85 easier. (Save some effort compared to using a programmer to program the ATtiny85.) For the Digispark, it comes loaded with a Digispark bootloader which allows user to program the ATtiny85 directly by plugging the board into the USB port. Below shows the pinout of the Digispark. (For reference)

digispark-pinout

 

Beam photoelectric infrared Sensor (LM393)

hr0172-irbeam

The Beam photoelectric infrared Sensor is a beam through sensor, which means that whenever an object passes through the sensor, the sensor output state will change accordingly. For this sensor, when the sensor is obstructed, it outputs a digital HIGH. Otherwise, it will output a digital LOW. The simplified workings of this sensor would look something like this, where OUT is the output pin.

ir_sch

 

Parts Required

Below are the parts required for this tutorial:

  • Digispark
  • Beam photoelectric infrared Sensor
  • Jumper wires
  • Mini breadboard (Optional)

Setting Up

Digispark Driver

Before commencing on the main objective, we first have to setup the Digispark. As the computer would not recognise the Digispark when you plug it in, we have to install the USB driver for it. To do so, download the following package here (Select the DigisparkArduino-Win32-1.0.4-May19). Extract the contents.

digispark_driver

Navigate to

DigisparkArduino-Win32 > DigisparkWindowsDriver

and run InstallDriver.exe to start installing the USB driver.

 Arduino IDE

We’ll be using the Arduino IDE to program the Digispark. The Digispark uses Arduino IDE 1.6.5 and above, so make sure to upgrade your Arduino IDE accordingly if you need to. For the Arduino IDE, we have to download the board configuration for the Digispark. To do so, go to File > Preferences.

ard-pref

In the preference, insert the following link in the Additional Boards Manager URLs and click OK.

http://digistump.com/package_digistump_index.json

ardpref-digispark

Next, go to Tools > Boards > Boards Manager. Search for Digi and install the Digistump AVR Boards entry.

ardboard-digi

After installation, goto Tools > Boards again,  but this time we would select the Digispark (Default – 16.5mhz) option. This is to tell the Arduino IDE that the board we will be using is the Digispark board.

ardselect-digi

Hello World

We’ll be uploading the traditional “Hello World” sample into the Digispark to ensure that the board is able to communicate with the computer. To do so, we’ll be uploading a simple blink sketch into the Digispark. (File>Examples>Digispark_Example>Start)

Before uploading the sketch, unplug you Digispark first. Next, press the upload sketch button & wait for it to be compiled. When the console/log at the bottom of the Arduino IDE displays Plug in device now…, plug the Digispark back in.

ard-digi-consl

If the status shows Micronucleus done. Thank you! , it means that the program has successfully being uploaded.

ard-digi-consl2

With that, let’s move on to interfacing the sensor with the Digispark.

NOTE: Apparently, the Digispark can only be detected using only USB2.0, so if you plug it in a USB 3.0 port, the computer may not be able to detect the Digispark.

 

Interfacing

We’ll now be interfacing the sensor with the Digispark. Connect the Digispark and the sensor as shown below. We’ll be using pin P2 for reading the sensor’s output.

ard-digi-sens-sch

Below are a few images of how the connection should look like:

 

Code

Basically how the Digispark will function is that whenever the sensor is blocked, the LED on the Digispark will light up. If not, the LED will remain off.

 

Demo

A short demo of the code.

digi_demo

Share this post:

You may also like...

Leave a Reply