5. E-textiles¶
What are we doing this week?¶
Tools¶
What is a circuit?¶
How do they work?¶
-
Power Source: This provides the energy needed to drive the current, commonly a battery or power supply.
-
Conductors: Wires made of conductive materials, like copper, allow electricity to flow between components. For this assignment we used conductive thread and conductive tape.
-
Resistors: These limit the amount of current flowing through the circuit. They are crucial for protecting sensitive components, such as LEDs, from too much current.
-
LEDs (Light Emitting Diodes): These light up when current passes through them. They require a certain amount of voltage and current, so they must be paired with a resistor to prevent damage.
-
Switches: These allow you to open or close the circuit, controlling whether the current can flow.
Tips for Creating Circuits¶
Things to Avoid:
-
Incorrect Component Values: Using the wrong resistor value can lead to too much current flowing to an LED, causing it to burn out. Always calculate the correct resistor value for your components.
-
Short Circuits: This occurs when there is an unintended path for the current, which can lead to overheating or damage. Ensure connections are secure and well-planned.
-
Overloading Components: Make sure each component can handle the voltage and current it will receive. Check the specifications to avoid damaging parts.
-
Poor Connections: Loose or poorly soldered connections can create resistance or intermittent failures. Always ensure good contact between wires and components.
Things to Do:
-
Plan Your Circuit: Sketch your circuit diagram before building. This helps you visualize the connections and components needed.
-
Test Your Circuit: Before powering up, double-check connections and component placements. A multimeter can help verify that everything is connected correctly. This step will save you a lot of time!!!
-
Use a Breadboard: For prototyping, use a breadboard to easily make changes without soldering. This allows for quick testing and adjustments.
-
Follow the Correct Polarity: Pay attention to the polarity of components like LEDs. Connecting them backward can prevent them from working or damage them.
Types of circuits¶
Building in parallel¶
In a parallel circuit:
-
Multiple Paths: Each component is connected to the same voltage source but has its own path for current to flow. This means that if one component fails, the others can still function.
-
Voltage Consistency: All components in a parallel circuit receive the same voltage, which is equal to the voltage of the power source.
-
Current Division: The total current flowing from the power source is divided among the parallel branches. The amount of current through each branch depends on the resistance of the components in that branch.
-
LEDs: When connecting multiple LEDs in parallel, each one will shine brightly at the same voltage.
Circuit Language¶
Here is some helpful information you may need to draw a circuit plan and to understands others work.
Working with Arduino¶
First steps¶
-
Install the Arduino IDE: Download and install the Arduino Integrated Development Environment (IDE) from the official Arduino website. This is where you'll write and upload your code.
-
Connect Your Arduino: Use a USB cable to connect your Arduino board to your computer. This will also power the board.
-
Select Your Board and Port: In the Arduino IDE, go to Tools and select the type of Arduino board you are using. Then select the appropriate port.
-
Understand the Arduino board:
Understanding the code¶
-
int ledPin = 13;
: This line sets the LED pin to 13, which is often where the built-in LED is located on Arduino boards. -
setup()
function: This runs once when you power the board. It sets the pin mode for the LED as an output. -
loop()
function: This runs repeatedly. It turns the LED on, waits for a second, turns it off, and waits another second, creating a blinking effect.
Common Problems and Solutions¶
-
Upload Issues: If you encounter an error when uploading your code, check that you’ve selected the correct board and port in the Arduino IDE. Also, ensure the board is properly connected to your computer.
-
LED Not Lighting Up: If the LED doesn’t blink, verify the wiring. Make sure the longer leg of the LED is connected to the correct pin and that the shorter leg is connected to ground (GND).
-
Code Errors: If you see error messages in the IDE, carefully read them. They often indicate issues. You can also copy the error message and google it.
-
Power Issues: If the board doesn’t power up, check the USB connection and try a different cable or port.
Results¶
Digital circuit: Loves me / Loves me not¶
Analog sensor: Twinkle, Twinkle, Little Star¶
Here you ca find the Arduino code I used
// Define the pins
int waterSensorPin = A0; // Water level sensor connected to analog pin A0
int led = 3; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 7; // how many points to fade the LED by
void setup() {
// Initialize serial communication at 9600 bits per second
Serial.begin(9600);
// Initialize the LED pin as an output
pinMode(led, OUTPUT);
}
void loop() {
// Read the input on analog pin 0
int sensorValue = analogRead(waterSensorPin);
// Print out the value you read
Serial.print("Water Level: ");
Serial.println(sensorValue);
// Check if the water level is above a threshold
if (sensorValue > 400) { // Adjust the threshold as necessary
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
} else {
digitalWrite(led, LOW); // Turn the LED off
}
}
Helpful Codes¶
int led_pin = 3; //define the pin where the Led is connected
void setup() {
pinMode(led_pin, OUTPUT); //define pin of the Led as an output
}
void loop() {
digitalWrite(led_pin, HIGH); //turn the Led on
delay(1000); //wait 1000millisecond
digitalWrite(led_pin, LOW); //turn the Led off
delay(1000); //wait 1000millisecond
}
/*
Fade - part of the Examples of Arduino IDE
This example shows how to fade an LED on pin 9 using the analogWrite()
function.
The analogWrite() function uses PWM, so if you want to change the pin you're
using, be sure to use another PWM capable pin. On most Arduino, the PWM pins
are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Fade
*/
int led = 3; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
/* we read the value of a digital sensor connected to pin digital_sensor_pin and
* we print it on the Serial Monitor
*/
int digital_sensor_pin = 8; //change the pin, where the sensor is connected?
int digital_sensor_value = 0;
void setup() {
// put your setup code here, to run once:
pinMode(digital_sensor_pin, INPUT); //define the pin as INPUT
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
digital_sensor_value = digitalRead(digital_sensor_pin); // read the sensor
Serial.println(digital_sensor_value); //print the value
delay(100);
}
/* this skecth is a modification of the example button!!
*/
int digital_sensor_pin = 7; //change the pin, where the sensor is connected?
int digital_sensor_value = 0;
int led_pin = 3; //change the pin of the Led
void setup() {
// put your setup code here, to run once:
pinMode(digital_sensor_pin, INPUT);
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(led_pin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digital_sensor_value = digitalRead(digital_sensor_pin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if(digital_sensor_value == HIGH){
// turn LED on:
digitalWrite(led_pin, HIGH);
} else {
// turn LED off:
digitalWrite(led_pin, LOW); // turn the LED off by making the voltage LOW
}
}
/* with this sketch we read the analog sensor connected to pin analog_sensor_pin
*/
int analog_sensor_pin = A0; //change the pin, where the sensor is connected?
int analog_sensor_value = 0;
void setup() {
// put your setup code here, to run once:
pinMode(analog_sensor_pin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
analog_sensor_value = analogRead(analog_sensor_pin); //read the Voltage of the pin sensor
Serial.println(analog_sensor_value); // print the value on the Serial monitor
delay(100);
}