Assignment 1 - Working circuit

Circuit with self made input and actuator as an output

Understanding a sensor and an RGB LED

The first thing I did was connecting a RGB Led. When I managed to change the colors I decided to connect it with a sensor, I used the ultrasonic sensor. The color changes whenever I get closer or further away from the sensor. This was the outcome:

#include <NewPing.h>
// ( trigger, echo, max cm)
NewPing sonar(5, 2, 20);

int greenPin = 3;
int bluePin = 4;

void setup() {
  // put your setup code here, to run once

  Serial.begin(9600);
  delay(50);

  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.print("The distance is:");
  Serial.println(sonar.ping_cm());
  delay(1000);
  if ((sonar.ping_cm()) > 10) {
    digitalWrite(greenPin, HIGH);
    digitalWrite(bluePin, LOW);
  }
  else {
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, HIGH);
  }
}

Connecting the sensor, motor and RGB LED

When I understood how you could connect a sensor with something else I added the actuator. Whenever I would come closer to the sensor, not only the color of the LED would change but the speed of the actuator as well, this was the outcome:

#include <NewPing.h>
// ( trigger, echo, max cm)
NewPing sonar(3, 4, 20);

int bluePin = 1;
int greenPin = 2;
int redPin = 6;
int motor = 5; 

void setup() {
  // put your setup code here, to run once

  Serial.begin(9600);
  delay(50);

  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(motor, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.print("The distance is:");
  Serial.println(sonar.ping_cm());
  delay(1000);
  if ((sonar.ping_cm()) > 0) {
    digitalWrite(greenPin, HIGH);
    digitalWrite(bluePin, LOW);
    digitalWrite(redPin, LOW);
    analogWrite(motor, 0);
    
  }
    if ((sonar.ping_cm()) > 5) {
    analogWrite(motor, 120);
  }
      if ((sonar.ping_cm()) > 8) {
    analogWrite(motor, 130);
  }
        if ((sonar.ping_cm()) > 10) {
    analogWrite(motor, 140);
  }
  if ((sonar.ping_cm()) > 12) {
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, HIGH);
    digitalWrite(redPin, LOW);
    analogWrite(motor, 150);
  }
          if ((sonar.ping_cm()) > 14) {
    analogWrite(motor, 180);
  }
   if ((sonar.ping_cm()) > 16) {
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
    digitalWrite(redPin, HIGH);
    analogWrite(motor, 200);
   }
             if ((sonar.ping_cm()) > 18) {
    analogWrite(motor, 230);
  }
               if ((sonar.ping_cm()) > 19) {
    analogWrite(motor, 255);
  }
}

L289N, first try building something with DC motor

When I thought I understood the components and the code well enough to build something that I liked I started looking into stuff that I wanted to build. I found that you can build a small car that can go forward and backward with an L298N and a switch. So I got that board and switch to try. I tried to control the speed of a motor with a potentiometer and control if the motor would go backwards or forwards with the switch. Unfortunately after a lot of trying I couldn't figure out why the motor wouldn't connect with my arduino through the l289N, so I gave up on this.

// L298N board by How to Mediatronics
#define enB 5
#define in3 14
#define in4 13

//toggle button
#define button 9

// defaults
boolean buttonState = LOW;
int rotDirection = 0;
int pressed = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(enB, OUTPUT);
  pinMode(in3, INPUT);
  pinMode(in4, INPUT);
  pinMode(button, INPUT);
  
// set initial rotation direction
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);

}

void loop() {
  int potValue = analogRead(A0); // Read potentiometer value
  int pwmOutput = map(potValue, 0, 1023, 0 , 255); // van 0-1023 naar 0-255
  analogWrite(enB, pwmOutput); // verzend potentiometer value naar l298n board
  // Read button - Debounce
  if (digitalRead(button) == true) {
    pressed = !pressed;
  }
  while (digitalRead(button) == true);
  delay(20);
  // If button is pressed - change rotation direction
  if (pressed == true  & rotDirection == 0) {
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);
    rotDirection = 1;
    delay(20);
  }
  // If button is pressed - change rotation direction
  if (pressed == false & rotDirection == 1) {
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);
    rotDirection = 0;
    delay(20);
  }
}

Making something without the L289N, second try

Because the DC motor did work without the L289N, i figured to just skip it. I've looked up on internet so many things and i tried a lot of different setups but I couldn't get it to work. I tried to make something without the L289N. Since I can not let it go backwards or forwards I figured that I can maybe make some propellor so that I wouldn't have to put the motor into the wheels. I made a sketch so that I knew what to build.

In my sketch I didn't had my sensor yet because I figured out later that a part of the assignment was to have an input that was made by yourself. I tried making a propellor out of a plastic bottle, I glued the motor into the lit:

I was pretty happy with the result so I continued building the car. I used small candles for the wheels and straws and sate sticks to connect it to the black board.

The car wasn't moving forward when I was blowing it with my own mouth so I figured that it wouldn't go forward with the propellor either. I thought it could be the wheels so I changed the wheels.

But it was still not moving forward when blowing it. I thought maybe I needed lighter material. So I used a plastic bottle, but it still didn't go forward unfortunately.

Another idea

When making the 3rd car still without success I decided to come up with another idea. I thought of stuff that turns. One of the first things that came in my mind was a windmill. I started making the windmill out of the carton of a toilet paper roll and made a hole in it for the motor.

It was pretty hard to make the hole of the square where the flags are attached to just as big as the turning part of the DC motor. I made it too big first and because of that it wouldn't turn anymore.

When the DC motor was working inside the windmill, I started making my sensor. First I decided to use the foam and set it up exactly as I did before with the crystal, but unfortunately that didn't work because there were no copper parts touching (loes told me).

Input week 6

I tried making something out of the conductive wire and fabric for a bit but unfortunately I only had a small needle where the wire couldn't go in to. So I decided making one of Loes' examples of the untoolkit week. If I would still have more time left I would've made another one made by myself.

End result

I decided to pimp it up a bit with some fake grass. I made the folding pressure sensor into a window and glued it on the side of the windmill. The windmill is on a 10x10 black swatch and the windmill itself is also black so that it fits the series of week 6. When i would have more time left I'd like to put led lights in the grass and controll them with a joystick.

Unfortunately my DC motor started working at the end (maybe a power failure?) It only worked for a few seconds and then I had to plug out the diode and plug it in again for it to work again for a few seconds. So that's why I can't show the working end result with the sensor in a video. I've tried a lot of different set ups and codes but I couldn't undeerstand why it suddenly didn't work anymore because it worked just fine before with the same setup.

This is the setup i've used for my DC motor. Besides this example I've put the sensor in +, GND on the breadboard and the i/o pin in A0 on my arduino board.

And this is the code I've wrote for the sensor and DC motor:

int drukSensor = A0;
int motor = 13;
int sensorValue = 0;

void setup() {
  // put your setup code here, to run once

  Serial.begin(115200);

  pinMode(drukSensor, INPUT);
  pinMode(motor, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);;
  sensorValue = analogRead(drukSensor);
  Serial.println(sensorValue);

  if (sensorValue > 10) {
    digitalWrite (motor, HIGH);
  }
  else {
    digitalWrite (motor, LOW);
  }
}

Reflection

In the beginning I was feeling full of inspiration, I had a lot of nice ideas. I really liked this assignment because you can do a lot of things with a DC motor. But after working on it everyday and one day even from 13:00 - 04:30 am, I got more and more frustrated because I hadn't the right materials at home to for example glue things together with a glue gun, or a good soldering iron to solder things together. I did try to make it work with the things I had. Besides not having the right tools, on the way to the end result, different, technical things went wrong a lot of times. For example, components in the circuit wouldn't work anymore when it did work a few minutes before and I had to build certain circuits over and over again just to find the mistake. When I would find the mistake and it worked again it was very satisfying. I am quite upset that I couldn't finish the assignment on time, while I put so much effort and time in it in my opinion. I did learn a lot about myself in this process. I learned that I have an insane amount of patience until I go nuts, haha. But everyday whenever waking up I would try again.

Last updated