Over the last couple weeks I have become interested in Arduino projects. An Arduino at it's very basic is a simple input/output device which uses a very simply programming language. More information about the Arduino project can be found at http://www.arduino.cc/
The main advantage I have is that it appears that I can start small and get more complicated as I progress.
The Raspberry Pi I bought, even though it is a very versatile piece of kit, is just collecting dust. I haven't used it at all,even though Maison graciously programmed it for me for the XBMC. It still seems far too complicated for me to sit down and learn the programming. Just getting the software onto the SD card seemed quite convoluted.
I must admit at this point that I don't like computers as they always seem to go too slow and don't do what I want when I want. Yes, I can use them to communicate etc but other than that I don't know bupkiss.
Anyway back to the Arduino.
I initially bought a starter pack from SainSmart via Amazon. The link is here. There are other starter kits available which cost more/less or have less/more equipment in it.
Although it is possible to find programs (or sketches as they're known in Arduino circles) on the web I decided I'd try and be a bit more structured by using a '....for Dummies' book, as I've found them easy to use in the past.
I am working my way towards an automated garden water system including water towers, solar charged batteries and irrigation systems.
So far I have tried a few projects from the built in examples but generally try and augment them a little bit to test my understanding of the sketch.
Project #1 - LED output dependant on variable resister input.
Uses a variable resister (pot) to set a value which is read by the Arduino. Depending on the value set, the Arduino will drive 1 of three led's. For some reason the green led is not as obvious as the red/blue ones
Uses a variable resister (pot) to set a value which is read by the Arduino. Depending on the value set, the Arduino will drive 1 of three led's and a piezo buzzer.For some reason the green led is not as obvious as the red/blue ones
Uses a sonic range finder with the time delay being read by the Arduino. Depending on the value read, the Arduino will drive 1 of three led's and a piezo buzzer. Similar to two previous projects. It just uses a different input device.For some reason the green led is not as obvious as the red/blue ones
Code after being augmented - '_20130622_EchoSounder_3LED_with_sound.ino'
The main advantage I have is that it appears that I can start small and get more complicated as I progress.
The Raspberry Pi I bought, even though it is a very versatile piece of kit, is just collecting dust. I haven't used it at all,even though Maison graciously programmed it for me for the XBMC. It still seems far too complicated for me to sit down and learn the programming. Just getting the software onto the SD card seemed quite convoluted.
I must admit at this point that I don't like computers as they always seem to go too slow and don't do what I want when I want. Yes, I can use them to communicate etc but other than that I don't know bupkiss.
Anyway back to the Arduino.
I initially bought a starter pack from SainSmart via Amazon. The link is here. There are other starter kits available which cost more/less or have less/more equipment in it.
Although it is possible to find programs (or sketches as they're known in Arduino circles) on the web I decided I'd try and be a bit more structured by using a '....for Dummies' book, as I've found them easy to use in the past.
I am working my way towards an automated garden water system including water towers, solar charged batteries and irrigation systems.
So far I have tried a few projects from the built in examples but generally try and augment them a little bit to test my understanding of the sketch.
Project #1 - LED output dependant on variable resister input.
Uses a variable resister (pot) to set a value which is read by the Arduino. Depending on the value set, the Arduino will drive 1 of three led's. For some reason the green led is not as obvious as the red/blue ones
Code after being augmented - '_20130622_Zippys_AnalogInOutSerial_3switch_led.ino'
c/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
modified 22nd June 2013 by Zippy : Added code for third LED.
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin09 = 9; // Analog output pin that the LED is attached to
const int analogOutPin10 = 10; // Analog output pin that the LED is attached to
const int analogOutPin11 = 11; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin); // map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255); // scale the input range(0-1023) from the pot
// to fit the output range (0-255) of the LED.
if (outputValue <= 1) {
analogWrite(analogOutPin09, 0); // with analogWrite you need to specify a number value between 0 and 255.
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 0);
}
if (outputValue > 1 && outputValue <;= 85) {
analogWrite(analogOutPin09, 255);
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 0);
}
if (outputValue >= 86 && outputValue <= 170) {
analogWrite(analogOutPin09, 0);
analogWrite(analogOutPin10, 255);
analogWrite(analogOutPin11, 0);
}
if (outputValue >= 171 && outputValue <= 255) {
analogWrite(analogOutPin09, 0);
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 255);
}
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 200 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(200);
}
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
modified 22nd June 2013 by Zippy : Added code for third LED.
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin09 = 9; // Analog output pin that the LED is attached to
const int analogOutPin10 = 10; // Analog output pin that the LED is attached to
const int analogOutPin11 = 11; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin); // map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255); // scale the input range(0-1023) from the pot
// to fit the output range (0-255) of the LED.
if (outputValue <= 1) {
analogWrite(analogOutPin09, 0); // with analogWrite you need to specify a number value between 0 and 255.
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 0);
}
if (outputValue > 1 && outputValue <;= 85) {
analogWrite(analogOutPin09, 255);
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 0);
}
if (outputValue >= 86 && outputValue <= 170) {
analogWrite(analogOutPin09, 0);
analogWrite(analogOutPin10, 255);
analogWrite(analogOutPin11, 0);
}
if (outputValue >= 171 && outputValue <= 255) {
analogWrite(analogOutPin09, 0);
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 255);
}
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 200 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(200);
}
¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
Project #2 - LED and buzzer output dependant on variable resister input.Uses a variable resister (pot) to set a value which is read by the Arduino. Depending on the value set, the Arduino will drive 1 of three led's and a piezo buzzer.For some reason the green led is not as obvious as the red/blue ones
Code after being augmented - '_20130622_Zippys_AnalogInOutSerial_3switch_led_with_sound.ino'
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
modified 23rd June 2013 - To include 3 LED's and a piezo buzzer by Zippy
piezo buzzer positive connected to pin 8 on the Arduino.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin09 = 9; // Analog output pin that the LED is attached to
const int analogOutPin10 = 10; // Analog output pin that the LED is attached to
const int analogOutPin11 = 11; // Analog output pin that the LED is attached to
int sensorValue = 0; // set initial value read from the pot
int outputValue = 0; // set initial value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255); // scale the input range(0-1023) from the pot
// to fit the output range (0-255) of the LED.
if (outputValue <= 1) {
analogWrite(analogOutPin09, 0); // with analogWrite you need to specify a number value between 0 and 255.
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 0);
noTone(8); // cancel tone to pin 8
}
if (outputValue > 1 &&; outputValue <= 85) {
analogWrite(analogOutPin09, 255);
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 0);
noTone(8); // cancel tone to pin 8
}
if (outputValue >= 86 && outputValue <= 170) {
analogWrite(analogOutPin09, 0);
analogWrite(analogOutPin10, 255);
analogWrite(analogOutPin11, 0);
tone(8,250); // tone(pin,freq[,optional duration]);
}
if (outputValue >= 171 && outputValue <= 255) {
analogWrite(analogOutPin09, 0);
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 255);
tone(8,500); // tone(pin,freq[,optional duration]);
}
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 200 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(200);
}
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
modified 23rd June 2013 - To include 3 LED's and a piezo buzzer by Zippy
piezo buzzer positive connected to pin 8 on the Arduino.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin09 = 9; // Analog output pin that the LED is attached to
const int analogOutPin10 = 10; // Analog output pin that the LED is attached to
const int analogOutPin11 = 11; // Analog output pin that the LED is attached to
int sensorValue = 0; // set initial value read from the pot
int outputValue = 0; // set initial value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255); // scale the input range(0-1023) from the pot
// to fit the output range (0-255) of the LED.
if (outputValue <= 1) {
analogWrite(analogOutPin09, 0); // with analogWrite you need to specify a number value between 0 and 255.
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 0);
noTone(8); // cancel tone to pin 8
}
if (outputValue > 1 &&; outputValue <= 85) {
analogWrite(analogOutPin09, 255);
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 0);
noTone(8); // cancel tone to pin 8
}
if (outputValue >= 86 && outputValue <= 170) {
analogWrite(analogOutPin09, 0);
analogWrite(analogOutPin10, 255);
analogWrite(analogOutPin11, 0);
tone(8,250); // tone(pin,freq[,optional duration]);
}
if (outputValue >= 171 && outputValue <= 255) {
analogWrite(analogOutPin09, 0);
analogWrite(analogOutPin10, 0);
analogWrite(analogOutPin11, 255);
tone(8,500); // tone(pin,freq[,optional duration]);
}
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 200 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(200);
}
¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
Project #3 - LED and buzzer output dependant on sonic range finder.Uses a sonic range finder with the time delay being read by the Arduino. Depending on the value read, the Arduino will drive 1 of three led's and a piezo buzzer. Similar to two previous projects. It just uses a different input device.For some reason the green led is not as obvious as the red/blue ones
Code after being augmented - '_20130622_EchoSounder_3LED_with_sound.ino'
c/*
HC-SR04 Ping distance sensor]
VCC to arduino 5v GND to arduino GND
Echo to Arduino pin 12 Trig to Arduino pin 13
Red POS to Arduino pin 11
Green POS to Arduino pin 10
560 ohm resistor to both LED NEG and GRD power rail
More info at: http://goo.gl/kJ8Gl
Original code improvements to the Ping sketch sourced from Trollmaker.com
Some code and wiring inspired by http://en.wikiversity.org/wiki/User:Dstaub/robotcar
*/
#define trigPin 13
#define echoPin 12
#define led1 9
#define led2 10
#define led3 11
// piezo buzzer positive attached to pin 6 on the Arduino
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 5) { // If the range is less than 5cm
digitalWrite(led1,HIGH); // For digitalWrite the value has to be either HIGH or LOW.
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
Serial.println("RED");
tone(6,600); // tone(pin,freq[,optional duration]);
}
if (distance >=5.5 && distance >=10) { // range is between 5.5 and 10cm
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
Serial.println("BLUE");
tone(6,200); // tone(pin[,optional duration]);
}
if (distance > 10 ){ // range is greater than 10cm
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
Serial.println("GREEN");
noTone(6); // cancel any tone sent to pin 6
}
if (distance >= 5000 || distance <= 0){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(250);
}
HC-SR04 Ping distance sensor]
VCC to arduino 5v GND to arduino GND
Echo to Arduino pin 12 Trig to Arduino pin 13
Red POS to Arduino pin 11
Green POS to Arduino pin 10
560 ohm resistor to both LED NEG and GRD power rail
More info at: http://goo.gl/kJ8Gl
Original code improvements to the Ping sketch sourced from Trollmaker.com
Some code and wiring inspired by http://en.wikiversity.org/wiki/User:Dstaub/robotcar
*/
#define trigPin 13
#define echoPin 12
#define led1 9
#define led2 10
#define led3 11
// piezo buzzer positive attached to pin 6 on the Arduino
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 5) { // If the range is less than 5cm
digitalWrite(led1,HIGH); // For digitalWrite the value has to be either HIGH or LOW.
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
Serial.println("RED");
tone(6,600); // tone(pin,freq[,optional duration]);
}
if (distance >=5.5 && distance >=10) { // range is between 5.5 and 10cm
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
Serial.println("BLUE");
tone(6,200); // tone(pin[,optional duration]);
}
if (distance > 10 ){ // range is greater than 10cm
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
Serial.println("GREEN");
noTone(6); // cancel any tone sent to pin 6
}
if (distance >= 5000 || distance <= 0){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(250);
}
¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
I have ordered some more components but will have to wait until I get back to FFA in July.












