SIDEBAR
»
S
I
D
E
B
A
R
«
Hello Arduino
February 19th, 2016 by Red Lion

It’s good to know a last year student because she can guide me through my Master’s programme…

So finally we started to play with arduino, which Riar called “a toy for grown-ups”. When I first got to know Wenya, a last year cohort, she told me they were making things with arduino boards and sent me some photos. I was like, “What?? Are you sure I’ll be okay with this?? I haven’t touched electronics for four years since I graduated from high school (and in my previous physics exams I often skip problems related to electronics because I sucked at it)”. She said I would be fine because it was pretty easy. So I went to find some books and websites related to arduino to try to get started. The projects in the books were pretty interesting though, but they still seemed difficult to me. Anyway, I have the teachers to teach me. I’ve paid my tuition fees to them so why should I spend time learning it on my own, I thought.

The “hello world” for arduino is a blinking LED light. Quite easy though. Both the code and the circuit (here I’d like to mention a background: in China students get to choose whether they want to study science or literature when they enter high school. Those who choose to study science will study physics, chemistry and biology, and literature students will study politics, history and geography. I used to study science, so I have background in electronics and circuits and stuff, but I hate electronics to be honest…I prefer mechanics. Trains! lol). Besides LED lights we also played with light dependent resistors and used Processing to detect its value. Perhaps I’ll use this technique to make stuff in the future.

Our assignment was to build an LED light that is dependent on the value of the light dependent resistor. When the value is high it turns off and when it’s low it turns on. I’ve struggled with where to put the “delay(500)” in the code, but eventually everything worked out fine. Here’s the video.

Here’s the code.

int inPin = A0;
int ledPin1 = 11;
int ledPin2 = 12;
int sensorVal = 0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:
//int sensorVal = 0;
analogWrite(ledPin1, 255);
sensorVal = analogRead(inPin);
Serial.println(sensorVal);
delay(500);//put delay before if so ledPin2 doesn’t delay
if (sensorVal < 500){
digitalWrite(ledPin2, HIGH);
}else{
digitalWrite(ledPin2, LOW);
}

analogWrite(ledPin1, 0);
sensorVal = analogRead(inPin);
Serial.println(sensorVal);
delay(500);
if (sensorVal < 500){
digitalWrite(ledPin2, HIGH);
}else{
digitalWrite(ledPin2, LOW);
}

}


Comments are closed

»  Substance:WordPress   »  Style:Ahren Ahimsa