Skip to content

Week 12: Output devices

Assignments:

  • Group assignment: Measure the power consumption of an output device. Document your work (in a group or individually)

  • Individual assignment: Add an output device to a microcontroller board you’ve designed and program it to do something.

What to learn:

  • Demonstrate workflows used in controlling an output device(s) with MCU board you have designed

Have you?

  • Linked to the group assignment page

  • Documented how you determined power consumption of an output device with your group

  • Documented what you learned from interfacing output device(s) to microcontroller and controlling the device(s)

  • Described your design and fabrication process or linked to previous examples.

  • Explained the programming process/es you used.

  • Outlined problems and how you fixed them

  • Included original design files and code

  • Included a ‘hero shot/video’ of your board

DOUBT: What is the point of the group excercise? Answer: Different output devices need different amounts of energy to function. You need to be able to choose suitable power source for your projects.

DOUBT:Is it ok to use the LED in the hello board as an output device for this assignment? Answer: No, you need to do more.

What are output devices?

Safety:

Important data to take into account when handling power:

  • With ~1 mA: it is OK, not much can happen

  • With ~10 mA it is enough to get a shock, contraction, loose control of the muscle.

  • With ~100 mA: there is fibrillation and possible heart attack

  • The body: has roughly M ohm externally and only a k ohm internally

  • The dielectric breakdown: ~kV/mm: voltage gradient that rips materials apart

  • Supply capacitors: we will be using power supplies that have capacitors

  • We will be using motors with coil, inductive flyback protection diodes connector polarization, orientation

  • Protection components in DigiKey

  • As in machines, don’t do power electronics alone, late at night, … Stay safe!!!!!

Power

Power electronics need power: This is a vendor we use for power supplies. This link helped me understand the different types of power supplies:

  • Switching supplies: noisy but inexpensive for lots of power. “Switching regulated power supplies are complex AC-to-DC power supplies that tend to combine the advantages of unregulated and regulated power supplies. In SMPS, the line voltage is rectified to DC, and then it is again converted to square wave AC with the help of switching transistors. This high-frequency square wave is then stepped down or stepped up and then again rectified. The rectified DC voltage is filtered before supplying it to a load.”

  • Linear(more expensive)

  • Regulated: if you know he current and voltage going into the device this gives you the power

This link to the Adrianino documentation shows how to connect different output devices, it is super helpful!!!. You can also check the different types of output devices on the fab academy website

Group assignment: Measure the power consumption of an output device. Document your work (in a group or individually)

Measuring the power consumption of a servo motor:

We have the following:

  • Arduino board which is connected to a servo motor. The yellow jumper wire connects the arduino to the servo motor by the PWM signal and is the cable to control the signal (it will tell the servo motor what way to move and how). The other two jumper wires are for power and can be connected to our computer for power (GND and VCC) but also to a power bench for more stable power supply. 1

  • We will hook it up to a power supply using PWM, giving it 5V as in the servo motor datasheet it says it typically works with 5V. 3

  • We will also connect it to an oscilloscope which will measure the servo motor voltage (the signal of the code we are sending to the servo motor). 2

  • This is how all the connections look like: 5 6

  • We put a code to the servo motor to make it do something, in the code: 0 is one way and 255 is the other way around(movement of the servo motor)

#define PIN_PWM 5

void setup() {
  pinMode(PIN_PWM, OUTPUT);
}

void loop() {
  analogWrite(PIN_PWM, 0);
  delay(1000);
  analogWrite(PIN_PWM, 127);
  delay(1000);
  analogWrite(PIN_PWM, 0);
  delay(1000);
  analogWrite(PIN_PWM, 255);
  delay(1000);
}
  • When we connect the code signal to the oscilloscope it says we are giving the arduino more power than we are giving it (around 40V) but this is impossible as the power bench does not even give more than 30V. We measured the voltage going to the Arduino from the power bench with the multimeter (as it is DC) and it said 5V. 7

  • Erwin then discovered there was a setting inside the oscilloscope that said that whatever you are measuring, amplify it by 10 We change it to norma and in 2V/division it shows a bit over 5V.

  • Setting the oscilloscope to DC Coupling, I had to look more about this and found a very understandable blog which explains difference between DC and AC coupling (far more than knowing there are two different types of currents). This explains “DC couples the entire signal to the screen, including constant positive or negative voltages. AC coupling will block the steady voltage, allowing you to observe small variations.”

  • It is now showing a signal which is already quite noisy, even though the servo motor is not really moving: 8

  • We zoomed in with the wheel time/division. The following video shows how the code sent to the servo motor is actually working as it is showing how the voltage moves from nothing to full to half and starts back again (movement set to the servo motor).

  • So the signal is working correctly, we then think the servo motors are not really working. We try connecting 2 different servo motors. Not working, maybe something wrong with the gears inside the motor?

  • Erwin then explains that the Arduino board has a regulator itself inside so when power is supplied to it and then supplied back to the servo motor it is passed through a regulator. We measure with the multimeter how much output current is given out and it was outputting 4V. We set the power supply to 7.5v and it starts giving an output of 5V. 10

  • The motor now starts moving (still a bit dodgy).

  • We now changed the different pin control signal to 5, so now pin 5 is the PWM instead of pin 3. 12

  • Servo motor starts working quite good.

  • The current spike shown below (yellow line that goes down) is when the motor is turned on/off. If there was a capacitor it would smooth that signal down.

  • This is the servo motor working with the power from a computer:

  • This is the servo motor working with the power from the power bench (there are more fancy electronics in the power supply that make the signal less noisy, makes the power supply more stable.

Measuring the power consumption of a regulator:

  • We have a regulator of 5V which means that if certain voltage comes through them they will transform it into 5V current coming out. They will burn the “waste” power. Erwin says they are quite inefficient because of this and that there are way better ways of regulating voltage. They also have a maximum voltage that can go through them, for example at 40V the would blow up.

  • We connect the regulator as following: one pin for power supply, second pin to ground, third pin is what is coming out (5V with this type of regulator). 18

  • We read the output voltage with one of the pins from the multimeter connected to the output pin of the regulator and the other pin to the output power coming out from the power supply, which said in fact 5V. 19 20

  • We then read the input voltage pin from the regulator which said 6.53V. So it was turning 6.53 V coming from the power bench to 5V.

Individual asssignment:

I am thinking of making a water-pump this week. Some questions I need to answer:

What components will I need?

What type of output device (motor?) will I use for this week?

I have to make a new board

Do I have to buy anything at a store?

What is a water-pump?

A water pump is an electrical device designed to take the already existing water and increase the rate at which that water is moving. When the water is speeding up in the pump, the device is creating low pressure at the intake, therefore creating a vacuum. Source

As the water is coming from the low-pressure side, the water outlet undergoes a higher pressure and the pushes the water with that force. They are various types of water pumps, but the two main categories that will be looked into in this article are the centrifugal water pumps and the positive displacement water pumps.

The final spiral version I would like to do: finalspiralversion finalspiralversion

Searching on the internet for similar projects but deconstructed (to start from basic prototypes) I found these very basic DIY projects: - very basic idea of a DIY water pump. firstspiral - very nice system of water pump firstspiral

From here I started thinking of components/ materials that I would need:

  • PVC pipe

  • DC motor (more pressure = larger motor): https://amzn.to/3fDB3FC

  • Impeller (pulls the water up) = I could 3D print it.

  • Micro-controller Which one? - Depends on the code

  • Battery 9V? Where is the voltage coming from? Some Amazon 9Volt battery references: 9volt, Hi-Watt 9V Battery, Duracell 9V Battery

  • Switch?​

  • Wires

After talking with Henk and showing him these examples he suggested I could use a distance sensor or a movement sensor (instead of a switch) so that when I passed the hand the water pump would be activated. I understood the system would work something like this: systemsketch

I got an Arduino UNO from the lab, some wires and starting trying out with some sensors. I first tried the PIR. From Nadieh’s documentation I learned how to use it. A PIR.

PIR PIR

  • Make sure that in the Arduino IDE you select the right board: PIR PIR https://www.makerguides.com/hc-sr501-arduino-tutorial/

Test movement sensor with Arduino. DC motors work with 5V

Used this code:

//To detect PIR
#define pin_PIR 2
int value;

void setup() {
  Serial.begin(9600);
}//void setup

void loop() {
  value = digitalRead(pin_PIR); //read state of the PIR

  if (value == LOW) {
    Serial.println("No motion");
  } else {
    Serial.println("Motion!");
  }//else

  delay(1000); 
}//void loop
  • This code worked:

Open global time:

  • On Saturday I connected to global open time and I got some good help from the team. Adrian gave me the link to his Adrianino part on motors. This was very helpful for my project. Although I did not necessary need the h-bridge for the water pump but in the end I decided to use it (explained below).

  • Pablo also shared a project from a last year student who used a pump to move water. He used this water pump. It is an underwater water pump DC 3V-5V. (Might come handy).

Trying out the DC motor

  • The transistor never arrived (corona times make post quite slow) so on Monday Henk helped me to find a way to to make it work.

  • First we tried connecting the motor with directly to the arduino board, for this Henk helped me to create a code:

//Make the motor move if there is motion from the PIR sensor
#define pin_PIR 2 //pin connected to PIR sensor
#define motor_pin 8 // pin connected to motor (VCC)
int value;

void setup() { 
  pinMode(8, OUTPUT);
  Serial.begin(9600);
}//void setup

void loop() {
  value = digitalRead(pin_PIR); //read state of the PIR

  if (value == LOW) {
    Serial.println("No motion");
  } else {
  digitalWrite(motor_pin, HIGH) ; //move motor if there is motion
    Serial.println("Motion!");
  }//else

  delay(1000); //How fast it receives the signals
}//void loop

motor motor motor motor

  • This did not work with the transistor we found at the lab (it was not the specific one) so Henk suggested I should use an H-bridge board.

  • The whole system would be something like this: motor

Nadieh explained me her tips on how to choose the correct chip when making your board: - look at the number of pins I need

  • look at if I will be doing easy things or more complicated things which will mean more memory consumption

  • load code + check the bytes used, then compare with the memory from the chip on their data sheet

  • Be careful with libraries because they consume most of the memory.

bytes bytes

So maybe the solution is use a DC board with h bridge and connect it to the at tiny 1614. pcbboard

TO-DO:

  • Know all the components I need

  • Draw 2 boards on Kicad

  • Mill boards

  • Buy a water pipe

  • Look for impellers that are DC motor size

  • Print out impellers + structure to pump water

  • Put everything together

Know all the components I need:

ATtiny 1614 board which will connect to the DC-motor board:

From this link and this link I understood the neccessary components for a ATtiny 1614. Henk recommended to use this IC as it has more pins and more memory. Also I think it is a good exercise to try different things.

Component Information Orientation Datasheet Why?
ATtiny 1614 ATTINY1614-SSFR Yes ATtiny 1614 Datasheet Controls board
UPDI header Conn_UPDI_01x02_Male Yes - So that board is programmed
FTDI header Conn_FTDI_01x06_Male Yes - To give power
Capacitor 1uF C_1206 No Capacitor Datasheet To reduce the noise of the chip
Switch Button BUTTON_B3SN Yes Button datasheet To turn on/off the motor
8 pin connector Conn_01x08_Male Yes - 2 pins are for 9V and GND for DC motor, 1 pin is for 5V coming from the IC, there are 4 input and output pins and 1 GND pin.
PIR sensor ? Yes PIR Datasheet 2 pins are for VCC and GND and one is connected to the chip
5mm adaptor for a DC Barrel Power Jack/Connector ? Yes ? to connect a 9V adaptor
Regulator NCP111 Yes - Regulator datasheet

I doubted between using a battery and the FTDI as I was considering it is water and I won’t want it to be constantly connected to my laptop but after talking with Henk we decided that it was better with the FTDI as I could then power it with a USB cable connected to a power adaptor.

I am also confused with the 8 pin connector Adrian uses with his Adrianino board as I am not using any extra power supply. Do I need so many pins? Or just GND, VCC and 2 digital outputs? I write a message to Adrian to solve my doubt: Hi Adrian! When you connect your Adrianino to the DC motor board with the Allegro you put an 8 pin connection. I am now doing a board with the ATtiny 1614, powered by FTDI, which connects to your DC motor board. In this case, how many pins in the connections would I have to use? I understand there should be a VCC, GND and two digital output pins right? I am confused as I am not using an extra power supply (like the battery you have).

DC-motor board:

Component Information Orientation Datasheet Why?
H-bridge driver Allegro A4953 driver Yes Allegro A4953 Datasheet This control the direction in the motor
Capacitor 1uF C_1206 No - To reduce the noise from the chip
Capacitor 10uF C_1206 No - To reduce the noise from the chip
8 pin connector C_1206 No - Connected to two digital outputs from the ATtiny 1614
4 upwards pin connector C_1206 No - To connect the DC-motor

Creating the 2 schematics and pcb boards on Ki-Cad:

ATtiny 1614 board:

  • I placed all components with no problems except for the 5mm adaptor which I did not even know the name for this. What I did look for the Arduino UNO components (as I knew this board had one). Found it! It is called a Power jack (Barrel connector). I looked for it in the symbol library from Ki-Cad and found one, although I was not sure if it was the correct one. I looked for its datasheet but just came across witha forum about the 2mm Barrel connector. I guess the 2mm does not matter as it refers to the size of the plug. Here I find the following image: schematicjack

  • I check the schematic diagram and realise it is the same as the one I have in Ki-Cad. Now I have to look for the footprint. I found lots of different types of footprints for the Power Jack Barrel Connector; Option 1, Option 2, Option 3. I also read from the forum: “There is no standard footprint for a DC jack connector. There are too many variants of this connector out there. You can have round holes, SMD, slots, switched pin on the right or on the left. As JRE commented, get the manufacturer’s datasheet and use the recommended footprint.” As I was not sure which one we had in the studio I had to wait till the following day to complete the schematic. Meanwhile I annotated, and created labels for the rest of the components.

  • I chose the correct regulator checking the fab inventory and comparing it to the Regulator I was using. In kicad’s fab library it was the following: correctregulatorkicad

  • To connect everything properly I checked the connections in de Adrianino and compared them to the ATtiny 1614 pinout: attinypinout

Some doubts to ask Henk before milling and to finish the schematic: - One question I have is why when we create the schematic add the VCC and GND to the capacitor, is this always like this? What happens when we have two capacitors? OKAY - Why did you say I had to leave the FTDI? TO DEBUG - The ATtiny is powered by 5V? So we have to power both boards with two cables? No, just in case. - One connection from the switch goes to the ATtiny and one goes to GND? YES - Where do I place the power flags? in both? Power flags are not that important - What footprint should I assign to the Jack? Option 3 was the corresponding with what we had in the studio. So I downloaded the footprint from here and added it to the PCB footprint library as I did in my input devices week for the gas sensor. OKAY - Look at its schematic to connect it OKAY

  • I had a lot of problems trying to understand the Jack connector, in this schematic I tried to understand how to connect it. schematic

  • This would be connected to this: 9v

  • After answering the questions this is the final result of the schematic: schematic

  • Ran the PCB checker, and had some problems: schematic

  • I realised I did not have my power sources arranged properly. I have power source coming from the FTDI and power source coming from the 9V but the 5V current was not associated to the 9V supply. So I added a GND label in the GND from 9V also: schematic

  • I assigned all footprint correctly. To change a footprint you just have to click twice on it.

  • In the PCB design don’t forget the design rules: designrules designrules

  • When doing the PCB design I had a lot of probelms making the traces, also the 5mm adaptor footprint would not have all the pads I needed, I tried downloading other 3 options but none of them showed the VCC pad I needed (and which I had placed in the schematic). This was a problem because I needed that pad as this was the power source of my board. footprint footprint

  • I then placed a 2 pad like in the Adrianino which I would connect to the power source, the following image was really helpful throughout the whole schematic and pcb design: adrianino

  • When exporting to Photoshop and then to mods, I realised there were a lot of extra traces which I did not need and also pads which would were too close to the traces (they would not be milled properly). I went back to KiCad and together with Henk we took all the extra traces and fixed the pads. I exported it back to Photoshop and starting milling it.

  • I had to cut off some traces but overall the board was quite good!

  • I soldered all the components looking at all the datasheet above. I specially worked out how to place the button using the multimeter (to check continuity within terminals). Then you don’t need to know which is GND and which is BUTTON because they both work as both.

DC motor board:

Some doubts to ask Henk before milling and to finish the schematic: - Why does he use 4 pins Adrian answered this question, it is because you need to make it more stable (Neil also uses this). Which one should I use? schematic

  • I have to look for a footprint for this one The footprint I used for this was 2 CONN 1x02 and in the schematic I just connected them like this: schematic

  • To connect the pins correctly to the Allegro driver I checked the pinout: pinout

  • After answering the questions this is the final result of the schematic: schematic

  • Which one of the capacitors goes first and why? The capacitors are interchangable, they do not require a specific order, Adrian also taught me this, so you don’t really need to put one before the other. I also changed the way you connect them in the schematic: schematic schematic schematic

  • Final PCB design: in this step I did not have many problems because I followed Adrian’s board and also they weren’t that many components. pcbboard pcbboard

  • When soldering I learned that header pins are just extension of the traces. When soldering the pin that connects to the motor I learned these are not connected between them.

  • This is the final result of the two board: pcbboards pcbboards

  • We soldered a 9V adaptor to two jumper wires to connect the power source, we then used some shrinking tube like I explain in the input devices week: solderingpowersource solderingpowersource

  • These are the final pieces: connectingboards connectingboards2

Testing out the board with code:

  • I open Arduino IDE and select the Port and the ATtiny 1614: ArduinoIDE

  • I connect the board to Arduino IDE with the UPDI and the FTDI and upload the code I did with Henk on Monday, I just modified the pin numbers:

//Make the motor move if there is motion from the PIR sensor
#define pin_PIR 7 //pin connected to PIR sensor
#define motor_pin 4 // pin connected to motor (VCC)
int value;

void setup() { 
  pinMode(8, OUTPUT);
  Serial.begin(9600);
}//void setup

void loop() {
  value = digitalRead(pin_PIR); //read state of the PIR

  if (value == LOW) {
    Serial.println("No motion");
  } else {
  digitalWrite(motor_pin, HIGH) ; //move motor if there is motion
    Serial.println("Motion!");
  }//else

  delay(1000); //How fast it receives the signals
}//void loop
  • Nothing appeared in the serial monitor. Henk said it was maybe that the FX and the RX were the other way around(I learned that in order to exchange information correctly RX should connect with TX and vcvs). I later on realised I had done the connection right but I used the following FTDI anyway cause I discovered this later (maybe I had not opened the correct port in the Arduino IDE at first): rxtx

  • Henk gave me an FTDI where you can connect the pins with jumper wires (so you can exchange the pins with wires): ftdi

Hello echo world
  • When connecting the ATtiny1614 to the UPDI and the computer I confused the port on the ATtiny1614 board for the UPDI and some smoke came out from my UPDI. My UPDI had broken because of wrong VCC and GND connections BE CAREFUL WITH THIS This is the message that appeared in my laptop before the short: short

  • I had to mill and solder a new UPDI. In the process I confused I milled the FTDI!! Henk showed me that I could mill a UPDI connection for the FTDI. So I milled and soldered this instead: newupdi

  • If you connect it to a FTDI, it turns into a UPDI: newupdi2

  • First, I will run the hello echo world on the ATtiny1614. For this I look for the ATtiny1614 Arduino hello echo world code.I understood AGAIN this week that running hello echo world on the serial monitor on Arduino IDE is the same as in the terminal. But I also wrote about the terminal pyupdi steps as this week I understood it much more than in the embedded programming week.

ARDUINO IDE:

  • I pasted the code from Neil to program the hello echo program to my ATtiny1614 board in the Arduino IDE. 1

  • I verified it/saved it (so that the hex file is saved in the build folder, I had already done in previous weeks) 2

  • I upload the code to the board and change the port so that it starts communicating with the FTDI instead of the UPDI now. 3

  • Open the serial monitor and change the baud rate as stated in the code from Neil: 4

  • Hello echo board is working: 5

TERMINAL

  • First I upgraded pip:
pip3 install --upgrade pip==21.1.1 
  • Then I did:
pip3 install https://github.com/mraardvark/pyupdi/archive/master.zip
  • And finally you put the hello echo world code with the corresponding details (chip you are using, baud rate, the device name of your UPDI, and the hex file name you find when compiling the code in Arduino IDE).
pyupdi -d tiny1614 -b 57600 -c /dev/cu.usbserial-D30A3 -f ~T/arduino_build_972268/Arduino1614hello_echo_world.ino.hex -v
  • Where to find the hex file: hexfile

  • Then you type hello and the board will respond (just like in the serial monitor).

Testing PIR sensor

For all the following steps I had to constantly look at the schematic of the ATtiny1614: schematic

To test the PIR I connect UPDI and FTDI to the board and upload the following code in Arduino IDE, specifying the PIR sensor pin:

//Measure the PIR motion detection
#define pin_PIR A7
int value;

void setup() {
  Serial.begin(9600);
}//void setup

void loop() {
  value = digitalRead(pin_PIR); //read state of the PIR

  if (value == LOW) {
    Serial.println("No motion");
  } else {
    Serial.println("Motion!");
  }//else

  delay(100); 
}//void loop
  • I change the port to the FTDI and open the serial monitor to see if motion and no motion appears:
Testing PIR sensor with motor
  • I tried the following code I had done with Henk but it did not work:
//Make the motor move if there is motion from the PIR sensor
#define pin_PIR A7 //pin connected to PIR sensor
#define motor_pin A4 // pin connected to motor (VCC)
int value;

void setup() { 
  pinMode(A4, OUTPUT);
  Serial.begin(9600);
}//void setup

void loop() {
  value = digitalRead(pin_PIR); //read state of the PIR

  if (value == LOW) {
    Serial.println("No motion");
  } else {
  digitalWrite(motor_pin, HIGH) ; //move motor if there is motion
    Serial.println("Motion!");
  }//else

  delay(1000); //How fast it receives the signals
}//void loop
  • Then I tried changing the pin for the one of outputmotor 2 but it also did not work:
//Make the motor move if there is motion from the PIR sensor
#define pin_PIR A7 //pin connected to PIR sensor
#define motor_pin A5 // pin connected to motor (VCC)
int value;

void setup() { 
  pinMode(A4, OUTPUT);
  Serial.begin(9600);
}//void setup

void loop() {
  value = digitalRead(pin_PIR); //read state of the PIR

  if (value == LOW) {
    Serial.println("No motion");
  } else {
  digitalWrite(motor_pin, HIGH) ; //move motor if there is motion
    Serial.println("Motion!");
  }//else

  delay(1000); //How fast it receives the signals
}//void loop
//Fab Academy 2020 - Fab Lab León
//Motor
//Adrianino
//ATtiny1614
const int switch1Pin = A6;     // switch 1        
const int motor1Pin = A4;      // H-bridge pin 0 (in2) 
const int motor2Pin = A5;      // H-bridge pin 1 (in1) 

void setup() {
    // set the switch pins as input pins and activate their internal pull up resistors
    // so they are not in a floating state because their default state is now HIGH
    pinMode(switch1Pin, INPUT); 


    // set H-bridge pins as outputs:
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
  }

void loop() {
    // if switch1 is pressed, (=LOW because the unpressed 'pulled up' state is HIGH)

  if (digitalRead(switch1Pin) == LOW) {
      analogWrite(motor1Pin, 127); // set pin 1 of the H-bridge to 50% using PWM
      analogWrite(motor2Pin, 0);   // set pin 2 of the H-bridge to low state
    }
     // if neither of the switches are pressed, the motor will stand still
  else
      {
      digitalWrite(motor1Pin, LOW);   // set pin 1 of the H-bridge low
      digitalWrite(motor2Pin, LOW);   // set pin 2 of the H-bridge low
      }
  }
Testing button
  • This did not work so I tried checking if the button was responding with his code from Neil, defining the button pin:
  //
// hello.button.serial.ino
//
// button serial hello-world
//    Arduino libraries: 1718 bytes, 41% tiny412 memory
//
// Neil Gershenfeld 11/3/20
//
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose, but must
// acknowledge this project. Copyright is retained and
// must be preserved. The work is provided as is; no
// warranty is provided, and users accept all liability.
//

#define button A6

void setup() {
   //
   // start serial
   //
   Serial.begin(9600);
   //
   // turn on button pull-up
   //
   pinMode(button,INPUT_PULLUP);
   }

void loop() {
   //
   // wait for button down
   //
   while (digitalRead(button) != LOW)
      ;
   Serial.write('d');
   //
   // wait for button up
   //
   while (digitalRead(button) == LOW)
      ;
   Serial.write('u');
   }
  • It worked, REMEMBER SWITCHING TO FTDI PORT EVERYTIME YOU WANT TO CHECK THE SERIAL MONITOR buttonresponding
Testing motor
  • Now I tried the motor again but in this case I tried giving it 9V external power (maybe it was not working because it needed more power). REMEMBER TO FIRST CONNECT GND AND THEN VCC and also BE CAREFUL WITH THE PINS ATTACHED TO THE MOTOR, IF THEY TOUCH BETWEEN THEM YOU GET A SHORT-CUT This was how I connected the boards: connectingboards

I connected JUST THE 9V, if you connect 5V and 9V at the same time you get a short, the picture is quite confusing in this sense

//Fab Academy 2020 - Fab Lab León
//Motor
//Adrianino
//ATtiny1614
const int switch1Pin = A6;     // switch 1        
const int motor1Pin = A4;      // H-bridge pin 0 (in2) 
const int motor2Pin = A5;      // H-bridge pin 1 (in1) 

void setup() {
    // set the switch pins as input pins and activate their internal pull up resistors
    // so they are not in a floating state because their default state is now HIGH
    pinMode(switch1Pin, INPUT); 


    // set H-bridge pins as outputs:
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
  }

void loop() {
    // if switch1 is pressed, (=LOW because the unpressed 'pulled up' state is HIGH)

  if (digitalRead(switch1Pin) == LOW) {
      analogWrite(motor1Pin, 127); // set pin 1 of the H-bridge to 50% using PWM
      analogWrite(motor2Pin, 0);   // set pin 2 of the H-bridge to low state
    }
     // if neither of the switches are pressed, the motor will stand still
  else
      {
      digitalWrite(motor1Pin, LOW);   // set pin 1 of the H-bridge low
      digitalWrite(motor2Pin, LOW);   // set pin 2 of the H-bridge low
      }
  }
  • It started working! Quite quickly I have to say. Now that I know that it works I will make a better connection between the jumperwires and the motor (to avoid any possible short circuit). I soldered it and done!

Build water pipe system:

  • This board is meant to control a simple water pipe system. After browsing the internet for some examples I found this really good waterimpeller. This one was perfect as I was looking for one that would work for the DC motor I was using.

  • This week I learned how to use the Prusa printer and I have to say I like it much more than the Ultimaker.

  • Firstly I loaded my material which is PTEG, I used this material because I read it is waterproof. I loaded it till halfway of the motorhead. prusa1 prusa2

  • I then switched on the Prusa with the on/off at the back. prusa3

  • The bed and the nozzle will heat up: prusa4

  • And you keep pressing No until you see your color filament coming out of the nozzle if it is not coming straight you should clean the nozzle with some paper carefully. prusa5

  • I did not calibrate it I just cleaned the bed with some paper and glass cleaning liquid so that the shape attachs to the bed: prusa6

  • I downloaded the Prusa slicer from here installed it and opened one of the parts that I had downloaded from Thingiverse. I added some support for the tube which is on the air: prusa9 prusa10

  • I saved all the parts in g-code: prusa11

  • I then chose my file in g-code and press, this will start printing: prusa7 prusa8

  • The pieces fit: prusa12 prusa13

  • These are all the parts: prusa14 prusa15 prusa16 prusa17

  • I soldered the motor to jumper wires and added screws to the water pump:

watersystem

Writing code for PIR sensor and motor

I first had to upload the code which said if PIR sensor senses movement then activate the motor, so I connected the board with FTDI and UPDI to upload this:

watersystem

I incorporated things to the motor to make this work:

//Make the motor move if there is motion from the PIR sensor

const int pirPin = 9; // PIR motion sensor pin
const int switch1Pin = A6;     // button pin       
const int motor1Pin = A4;      // H-bridge pin 0 (in2) 
const int motor2Pin = A5;      // H-bridge pin 1 (in1) 


void setup() { // the setup routine runs once when you press reset:

    // initialize the pir motion sensor pin as an input.
  pinMode(pirPin, INPUT); 

  pinMode(switch1Pin, INPUT); // set the switch pins as input pins and activate their internal pull up resistors
    // so they are not in a floating state because their default state is now HIGH

  pinMode(motor1Pin, OUTPUT);  // set H-bridge pins as outputs
  pinMode(motor2Pin, OUTPUT);
}


void loop() { // the loop routine runs over and over again forever:

  if (digitalRead(pirPin) == HIGH) { // if there is no value
  analogWrite(motor1Pin, 127); // set pin 1 of the H-bridge to 50% using PWM
  analogWrite(motor2Pin, 0);   // set pin 2 of the H-bridge to low state
    }

  else
      {
      digitalWrite(motor1Pin, LOW);   // set pin 1 of the H-bridge low
      digitalWrite(motor2Pin, LOW);   // set pin 2 of the H-bridge low
      }

  delay(1000); //How fast it receives the signals
}
Files for Output devices week
  • This is the Ki-CAD schematic file in PDF for the ATtiny board | KiCADschematic1

  • This is the Traces PNG for the ATtiny board | Traces1

  • This is the Interior PNG for the ATtiny board | Interior1

  • This is the Ki-CAD schematic file in PDF for the DC Motor board | KiCADschematic2

  • This is the Traces PNG for the DC Motor board | Traces2

  • This is the Interior PNG for the DC Motor board| Interior2


Last update: July 2, 2021