Task 1 Task 2 Task 3 Task 4 Task 5 Task 6  Homework Tasks

Analogue Input

1 Analogue Inputs

Learn It

  • First we need to connect the potentiometer(POT) to the breadboard.
  • You will need to bend the one leg of the POT back.

Bend_leg.jpg

  • Now remove the PTM switch.

Remove_switch.jpg

  • Now insert the POT just below where the switch was. Check where the legs go for the switch.

insert_pot_1.jpg

  • It should finally look like this.

Pot_in_place.jpg

Prepare Program

  • Here is a video explaining how to use the analogRead instuction.

  • You will now set up a program to monitor the Analogue input.
  • To do this, we are going to use the serial monitor.
  • The Arduino IDE has a feature that can be a great help in debugging sketches or controlling Arduino from your computer's keyboard. The Serial Monitor is a separate pop-up window that acts as a separate terminal that communicates by receiving and sending Serial Data.
  • First, open a new Arduino sketch. Call it AnalogInputOnly.
  • Then write the following code to it and download the program to your Arduino.
  • Once downloaded, you can click on the serial monitor button in the top right had corner and monitor the POT by turning it clockwise and anti-clockwise.

serial_monitor.jpg

  • Make sure the Baud rate is set to 9600, as it is set up in your program.

Baud_rate.jpg

  • You will now be able to see the value change as you adjust your POT between 0-1023.
  • The Genie microcontroller can set a value between 0-255.

Test It

  • Lets now write a program to control the LED when the POT is turned to a certain position.
  • If your LED was removed, replace it as it was previously in the breadboard.

Replace_LED.JPG

  • Now start a new sketch called AnalogTest and write the following program.

Analogue_switch_control.png

 

Badge It

  • Take a screenshot of your code and upload it to the badge task. Make sure you include the bottom, where it states 'Done uploading'.

Extension Tasks

  • Adapt your code so that...
    • The LED is off if the sensor value is under 300, on constantly if it's between 301-700 and flashing if it's over 700. Tip: 'else if' will help.
    • Add two more LEDs to other output pins. Adapt the code so that as the potentiometer is turned, either none, 1, 2 or 3 LEDs are lit.
    • Make the brightness of an LED change as the potentiometer is turned. Tip: You need to use a technique called PWM to achieve this.