The ForceTronics blog provides tutorials on creating fun and unique electronic projects. The goal of each project will be to create a foundation or jumping off point for amateur, hobbyist, and professional engineers to build on and innovate. Please use the comments section for questions and go to forcetronics.com for information on forcetronics consulting services.
Showing posts with label digital pin. Show all posts
Showing posts with label digital pin. Show all posts
Sunday, March 27, 2016
How to Protect your Arduino Design (Electrically) Part 1
In this video we look at how to protect your Arduino against different forms of electrical damage and ensure your design is electrically rugged. We will be looking at parts such as current limiting resistors, zenor diodes, and schottky barrier diodes.
Sunday, January 31, 2016
How to Reset Your Arduino from Code
In this video we talk about how to reset your Arduino from code with no hands. You can find the schematic and code from this video below.
int led = 13;
//create a variable for detecting what mode you are in. If used in interrupt must be "volatile"
/*volatile*/ bool nMode = 1;
void setup() {
pinMode(4, OUTPUT); //set up pin 4, which is connected to base of transistor
digitalWrite(4,LOW); //set to low so transistor is off and doesn't trigger reset
pinMode(led, OUTPUT); //set up the LED pin to output
Serial.begin(57600); //start serial comm
Serial.println("We just started back up"); //print quick message so we know we just went through setup code
Serial.println();
Serial.end(); //need to shut off serial comm because it uses interrupts
//Create interrupt: 0 for pin 2, the name of the interrupt function or ISR, and condition to trigger interrupt
attachInterrupt(0, interruptFunction, CHANGE);
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(400); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(400); // wait
/*
noInterrupts(); //disables interrupts
// critical, time-sensitive code here
interrupts();//enables interrupts
*/
}
//This is the function called when the interrupt occurs (pin 2 goes high)
//this is often referred to as the interrupt service routine or ISR
//This cannot take any input arguments or return anything
void interruptFunction() {
digitalWrite(4,HIGH); //with this variable set to 1 the LED will blink
//detachInterrupt(0); this function call will turn the interrupt off
}
***************Arduino Code from Video************************************
// Pin 13 has an LED connected on most Arduino boards.int led = 13;
//create a variable for detecting what mode you are in. If used in interrupt must be "volatile"
/*volatile*/ bool nMode = 1;
void setup() {
pinMode(4, OUTPUT); //set up pin 4, which is connected to base of transistor
digitalWrite(4,LOW); //set to low so transistor is off and doesn't trigger reset
pinMode(led, OUTPUT); //set up the LED pin to output
Serial.begin(57600); //start serial comm
Serial.println("We just started back up"); //print quick message so we know we just went through setup code
Serial.println();
Serial.end(); //need to shut off serial comm because it uses interrupts
//Create interrupt: 0 for pin 2, the name of the interrupt function or ISR, and condition to trigger interrupt
attachInterrupt(0, interruptFunction, CHANGE);
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(400); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(400); // wait
/*
noInterrupts(); //disables interrupts
// critical, time-sensitive code here
interrupts();//enables interrupts
*/
}
//This is the function called when the interrupt occurs (pin 2 goes high)
//this is often referred to as the interrupt service routine or ISR
//This cannot take any input arguments or return anything
void interruptFunction() {
digitalWrite(4,HIGH); //with this variable set to 1 the LED will blink
//detachInterrupt(0); this function call will turn the interrupt off
}
Subscribe to:
Posts (Atom)
