Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments. It is a physical computing platform based on a simple I/O board and a development environment that implements the Processing/Wiring language. Arduino can be used to develop stand-alone interactive objects or can be connected to software running on a computer.
The assignment was to blink a LED on a circuit board by burning a program into the Arduino microprocessor.
The ardunio code is given below:
/*This program makes an LED blink on the arduino board.*/
int ledPin = 13; // LED connected to digital pin 13
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
The first of the interactions with Arduino was to transfer signal from computer to the chip through serial port.
The code is given below:
Arduino Code:
int outputPins[] = {3,4,13};
//int outputPin = 13;
int val;
void setup()
{
Serial.begin(9600);
pinMode(outputPins[0], OUTPUT);
pinMode(outputPins[1], OUTPUT);
pinMode(outputPins[2], OUTPUT);
}
void loop()
{
if (Serial.available()) {
val = Serial.read();
if (val == 'a') {
digitalWrite(outputPins[0], HIGH);
delay(1000);
}
if (val == 'b') {
digitalWrite(outputPins[1], HIGH);
delay(1000);
}
if (val == 'c') {
digitalWrite(outputPins[2], HIGH);
//delay(1000);
}
if (val == 'e') {
digitalWrite(outputPins[0], LOW);
digitalWrite(outputPins[1], LOW);
digitalWrite(outputPins[2], LOW);
}
}
}
Processing Code:
import processing.serial.*;
Serial port;
void setup()
{
size(200, 200);
println(Serial.list());
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[1], 9600);
}
int value =0;
void draw()
{
fill(value);
rect(50,50,50,50);
}
void keyPressed() {
if (key == 'a' || key == 'A') {
value =255;
port.write('a');
}
if (key == 'b' || key == 'B') {
value= 200;
port.write('b');
}
if (key == 'c' || key == 'C') {
value=110;
port.write('c');
}
}
void keyReleased() {
value=0;
port.write('e');
}
Arduino Code:
int potPin = 2; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
Serial.begin(9600);
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time
Serial.print(val);
}
Processing Code:
import processing.serial.*;
Serial port;
int Length = 200;
int Width = 300;
void setup()
{
println(Serial.list());
size (Width, Length);
background(0,0,0);
port = new Serial(this, Serial.list()[1], 9600);
// frameRate(10);
}
int value =255;
void draw() {
fill(255);
rect(50, 50, 200, 100);
int val = port.read();
println(" " + val + " ");
fill(val);
rect(50, 50, 200, 100);
}