In this lesson we show you how to animate, or bring your Vpython objects to life by changing their parameters dynamically. In later lessons we will do this via life readings from sensors.
All posts by admin
Arduino Tutorial 37: Understanding How to Control DC Motors in Projects
In this lesson we learn the ins and outs of controlling a DC Motor from an Arduino. A key aspect of this is to understand you must not connect a motor directly to an arduino. You need to either build a suitable transistor and diode circuit, or you need to utilize a motor controller, such as the L293D motor control chip.
The video below explains how to hook things up and how the code works. You must always be mindful that you are using a motor with current requirements that are consistent with the motor controller and power supply you are working with. Failure to do so could result in damage to components or injury.
The circuit used in this video tutorial is shown below:
It is a good practice to have all grounds connected in a circuit, so I would connect an arduino ground to the ground rail of the breadboard. The components used in this project are from the Elegoo starter kit, which you can pick up HERE. The code is described in the video, but if you need help, this is the code we used in the lesson.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | int speedPin=5; int dir1=4; int dir2=3; int mSpeed=90; void setup() { // put your setup code here, to run once: pinMode(speedPin,OUTPUT); pinMode(dir1,OUTPUT); pinMode(dir2,OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: digitalWrite(dir1,LOW); digitalWrite(dir2,HIGH); analogWrite(speedPin,255); delay(25); analogWrite(speedPin,mSpeed); delay(5000); } |
9-Axis IMU LESSON 14: Introduction to Animating Objects in Vpython
In this lesson we need to become more comfortable working with objects in Vpython. WE will show how to create an animated thermometer using the simple commands we have already learned.
Arduino Tutorial 36: Understanding How to Use Tilt Switches in Your Projects
This is a simple project that allows you to create a circuit which will give a visual indication if the breadboard has been tilted. In the upright position, the Green LED is illuminated. To the left of the board is a tilt switch. If the project is tilted, the switch will go from the closed to the open condition. This can be detected on the arduino, and then the red LED is illuminated. The video below explains how to do this simple project.
You can get the kit we are using in these lessons HERE. You should create your own code based on the instructions in the video, but if you are having trouble, I include the code developed in the video below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | int tiltPin=2; int tiltVal; int redPin=7; int greenPin=6; void setup() { // put your setup code here, to run once: pinMode(tiltPin,INPUT); pinMode(redPin,OUTPUT); pinMode(greenPin,OUTPUT); digitalWrite(tiltPin,HIGH); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: tiltVal=digitalRead(tiltPin); Serial.println(tiltVal); if (tiltVal==0){ digitalWrite(greenPin,HIGH); digitalWrite(redPin,LOW); } if (tiltVal==1){ digitalWrite(greenPin,LOW); digitalWrite(redPin,HIGH); } } |
9-Axis IMU LESSON 13: Introduction to Visual Python (Vpython)
In this lesson we show you how to install Visual Python (Vpython) and show you how to begin to build 3D visuals. We introduce you to some of the basic objects and how how control how they look and where they are.